import java.util.Scanner;

public class Hanoi {
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter n: ");
        int n = sc.nextInt();
        hanoi(n,'f','a','t');
    }
    public static void hanoi(int n, char f, char a,char t)
    {
        if (n == 1)
        {
            System.out.println("Move " + n + " from " + f + " to " + t);
            return;
        }
        hanoi(n-1, f, t, a);
        System.out.println("Move " + n + " from " + f + " to " + t);//当前步骤的输出，与函数的输入有关
        hanoi(n-1, a, f, t);
    }
}
/*
* n=2，有两个圆盘的情况。
* hanoi(2,f,a,t)
*if (n == 1)
        {
            System.out.println("Move" + n + "from " + f + " to " + t);
            return;
        }                                                                                初始状态  =
        hanoi(1, f, t, a);                                                                       ===
        * {                                                                                       f      a      t
        * System.out.println("Move" + n + "from " + f + " to " + t);  1,f,a  将最小的从f 移动到 a -----------------------------------
        * }
        *                                                                                        ===     =
        *                                                                                         f      a      t
        System.out.println("Move" + n + "from " + f + " to " + t);   2，f,t  将最大的从f移动到t------------------------------------
        *
        *                                                                                                =     ===
        *                                                                                         f      a      t
        *
        hanoi(1, a, f, t);
        * System.out.println("Move" + n + "from " + f + " to " + t);  1, a , t  将最小的从a移动到t-----------------------------------------------------
        *                                                                                                       =
        *                                                                                                      ===
        *                                                                                         f      a      t
    }
* */
